# -*- coding: utf-8 -*-
"""
summary:
    文章模板
author:
    Jason Lee <huacnlee@gmail.com>
"""
from django.template import Library,defaultfilters
from utils import logs
from utils.helper import view
from apps.blog.models import Category
from settings import *
import traceback



register = Library()
__FILTER_NAME_PREFIX = "blog_componsent_sidebar_"
__template_root = 'blog/components/sidebar/%s'


def categorys(owner,size=100):
    """
    summary:
        sidebar分类列表html
    params:
        owner       (obj)        博客Profile对象
        size        (int)        最多显示多少个
    """
    cates = []
    try:
        cates = Category.objects.filter(profile__user__id = owner.user.id).order_by('sort')[:size]
    except:
        logs.write(traceback)

    data = {
            'owner' : owner,
            'cates' : cates,
            }

    return defaultfilters.safe(view.out_html((__template_root % ('categorys.html')),data))

def profile(owner):
    """
    summary:
        sidebar分类列表html
    params:
        owner       (obj)        博客Profile对象
    """
    data = {
            'owner' : owner,
            }

    return defaultfilters.safe(view.out_html((__template_root % ('profile.html')),data))

register.filter('%scategorys' % __FILTER_NAME_PREFIX, categorys)
register.filter('%sprofile' % __FILTER_NAME_PREFIX, profile)
